package com.scsj.supermarket.presenter;

import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.AddAndAlterDeliveryAddressBase;
import com.scsj.supermarket.base.AuthenticationBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.model.AddAndAlterDeliveryAddressModel;
import com.scsj.supermarket.model.AuthenticationModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 验证旧手机号presenter
 */

public class AuthenticationPresenter extends BasePresenter implements AuthenticationBase.IPresenter {

    private AuthenticationBase.IModel mModel;
    private AuthenticationBase.IView mView;

    public AuthenticationPresenter(AuthenticationBase.IView view) {
        mView = view;
        mModel = new AuthenticationModel();
    }


    @Override
    public void deliverSendSmsCodeData(RequestBody requestBody) {
        addSubscription(mModel.getSendSmsCodeData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.sendSmsCodeSuccessMsg("验证码发送成功", result);
                    Logger.d("验证码发送成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverVerifySmsCodeData(RequestBody requestBody) {
        addSubscription(mModel.getVerifySmsCodeData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.verifySmsCodeSuccessMsg("验证码正确", result);
                    Logger.d("验证码正确" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("核对验证码", msg + "");
            }
        }));
    }
}
